import { ElMessage, ElMessageBox } from "element-plus";

export function actionTip(
  api: any,
  data: any,
  fn?: Function,
  message: string = "确定修改?"
) {
  ElMessageBox.confirm(message, "Warning", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
  })
    .then(() => {
      api(data)
        .then(() => {
          ElMessage({
            type: "success",
            message: "修改成功",
          });
          if (fn) {
            fn();
          }
        })
        .catch(() => {
          ElMessage({
            type: "error",
            message: "修改失败",
          });
          if (fn) {
            fn();
          }
        });
    })
    .catch(() => {
      ElMessage({
        type: "info",
        message: "取消修改",
      });
    });
}
